﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Office.Interop.Excel;

namespace WFL.Office.Excel
{
    public class ExcelBorder : IDisposable
    {
        public Color Color
        {
            get
            {
                Color color = Color.Empty;
                int rgb = (int)(double)_border.Color;
                if (rgb != 0)
                {
                    byte[] bytes = BitConverter.GetBytes(rgb);
                    color = Color.FromArgb(255, bytes[0], bytes[1], bytes[2]);
                }
                return color;
            }
            set
            {
                _border.Color = BitConverter.ToInt32(new byte[] { Color.R, Color.G, Color.B, 0 }, 0);
            }
        }

        public ColorIndex ColorIndex
        {
            get { return (ColorIndex)_border.ColorIndex; }
            set { _border.ColorIndex = value; }
        }

        public LineStyle LineStyle
        {
            get { return (LineStyle)_border.LineStyle; }
            set { _border.LineStyle = value; }
        }

        public BorderWeight Weight
        {
            get { return (BorderWeight)_border.Weight; }
            set { _border.Weight = value; }
        }

        private Border _border;

        internal ExcelBorder(Border border)
        {
            _border = border;
        }


        #region IDisposable 成员

        public void Dispose()
        {
            if (_border != null)
            {
                Marshal.ReleaseComObject(_border);
                _border = null;
            }
        }

        #endregion

    }
}
